import hashlib

def freeze_node(seq): # modify seq
    if len(seq) == 1:
        return
    for item in seq[1:]:
        if not isinstance(item, basestring):
            break # for item
    else:
        seq[1:] = seq[1][0:0].join(seq[1:])
        return
    for item in seq[1:]:
        if not isinstance(item, basestring):
            freeze_node(item)

def calc_md5(fileName):
    m = hashlib.md5()
    f = open(fileName, "rb")
    try:
        m.update(f.read())
    finally: f.close()
    return m.hexdigest()

def calc_md5_bytes(bytes):
    m = hashlib.md5()
    m.update(bytes)
    return m.hexdigest()
